<template>
  <div>
    <el-dialog  :title="form.id ?'修改学科':'新增学科'" :visible="subjectsAddShow" v-bind="$attrs"  @open="onOpen" @close="close">
      <el-row :gutter="15">
        <el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="100px"
          label-position="left">
          <el-col :span="12">
            <el-form-item label="学科名称" prop="subjectName">
              <el-input v-model="form.subjectName" placeholder="请输入学科名称" clearable :style="{width: '100%'}">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开关" prop="isFrontDisplay">
              <el-switch v-model="form.isFrontDisplay" active-color="#04F819" inactive-color="#FF0000"></el-switch>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { add, update } from '../../api/hmmm/subjects.js'
export default {
  inheritAttrs: false,
  components: {},
  props: {
    subjectsAddShow:{
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        subjectName: undefined,
        isFrontDisplay: false,
      },
      rules: {
        subjectName: [{
          required: true,
          message: '请输入学科名称',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onOpen() {},
    close() {
      this.$refs['formRef'].resetFields()
      this.$emit('update:subjectsAddShow', false)
    },
    handelConfirm() {
      this.$refs['formRef'].validate(async valid => {
        if (!valid) return
        // 发请求
        this.form.id
        //  编辑
        ?await update(this.form)
        //  新增
        :await add(this.form)
        // 提示成功
        this.$message.success('操作成功')
        // 刷新列表
        this.$emit('success')
        this.close()
      })
    },
  }
}

</script>
<style>
</style>
